<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {
    function __construct(){
        //构造函数
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }
    
    public function index()
    {
        //默认初始化函数
        //--初始化整个首页的数据--
        //$this->load->view('header_v');
        //$this->load->view('login/login_main_v');
        //$this->load->view('footer_v');
        
        $this->load->view('register/register_main_v');
    }
    
    //注册函数
    public function do_register()
    {
        $data['name']= $this->input->post('name')       ;
        $data['pw']= $this->input->post('pw1');
        $data['question']= $this->input->post('question');
        $data['answer']= $this->input->post('answer');
        $data['phone']= $this->input->post('phone');
        //连接数据库
        $this->load->database();
        $sql = "INSERT INTO `xiaojiwang`.`user` (`id` ,`name` ,`password` ,`question_id` ,`answer` ,`user_name` ,`sex` ,`location` , `phone` , `qq` ,`email` ,`explain` ,`time` ,`life` )VALUES (NULL ,".$data['name'].", ".$data['pw'].",".$data['question'].",".$data['answer'].",NULL,NULL,NULL,".$data['phone'].",NULL,NULL,NULL,NULL,NULL)";
        $query = $this->db->query($sql);
        if ($this->db->affected_rows() > 0)
        {   
            echo "添加成功";
        }
        else {
            echo "添加失败!";
        }  
        $this->load->view('loginseccess_view',$data);
    }
}